<?php

/**
 * 落地页模型
 */

namespace app\common\model;

use think\model\concern\SoftDelete;
use think\model\relation\BelongsTo;

class Page  extends CommonBaseModel
{
    use SoftDelete;
    // 自定义选择数据


    protected $name = 'page';
    protected $autoWriteTimestamp = true;

    // 可搜索字段
    public array $searchField = [];

    // 可作为条件的字段
    public array $whereField = ['template', 'domain',];

    // 可作为多选条件的字段
    public array $multiWhereField = [];

    // 可做为时间
    public array $timeField = [];

    public static array $type_array = [
        [
            'id' => 'h5',
            'name' => 'H5'
        ],
        [
            'id' => 'app',
            'name' => 'APP'
        ]
    ];

    // 关联模板
    public function template(): BelongsTo
    {
        return $this->belongsTo(Template::class);
    }

    //获取随机数
    public function getRandom($length = 4, $numeric = 0)
    {
        $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';  
        $charactersLength = strlen($characters);  
        $randomString = '';  
          
        for ($i = 0; $i < $length; $i++) {  
            $randomString .= $characters[rand(0, $charactersLength - 1)];  
        }  
          
        return $randomString;  
    }
}
